package cn.jjxx.modules.map.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSON;

import cn.jjxx.core.common.controller.BaseController;
import cn.jjxx.core.utils.MessageUtils;
import cn.jjxx.core.utils.StringUtils;
import cn.jjxx.modules.map.service.ICommonMapService;

@Controller
@RequestMapping("${admin.url.prefix}/map/commommap")
public class CommonMapController extends BaseController{

	@Autowired
    protected ICommonMapService commonMapService;
	
	/**
	 * @Description: 跳转至数据库表信息界面 .<br>
	 * @param request http请求 .<br>
	 * @param response http响应 .<br>
	 * @author 郑成功 .<br>
	 * @date 2018-6-4 上午11:32:16.<br>
	 */
	@RequestMapping(value = "dbTablesList", method = RequestMethod.GET)
	public String bdTablesList(HttpServletRequest request, HttpServletResponse response){
		return display("dbTablesList");
	}
	
	/**
	 * @Description: 跳转至表结构信息界面 .<br>
	 * @param request http请求 .<br>
	 * @param response http响应 .<br>
	 * @author 郑成功 .<br>
	 * @date 2018-6-4 上午11:32:16.<br>
	 */
	@RequestMapping(value = "tablesInfoList", method = RequestMethod.GET)
	public String tablesInfoList(HttpServletRequest request, HttpServletResponse response){
		return display("tablesInfoList");
	}
	
	/**
	 * @Description: 获取数据库表信息列表 .<br>
	 * @param tableName 表名称 .<br>
	 * @param tableComment 注解名称 .<br>
	 * @author 郑成功 .<br>
	 * @date 2018-6-4 上午11:32:16.<br>
	 */
	@RequestMapping(value = "findDbTables", method = { RequestMethod.GET, RequestMethod.POST })
	public void findDbTables(HttpServletRequest request,HttpServletResponse response,
			String tableName,String tableComment){
		String dbName = MessageUtils.getMessage("connection.dbname");
		List<Map<String, Object>> list = commonMapService.selectDbTables(dbName, tableName, tableComment);
		String content = JSON.toJSONString(list);
        StringUtils.printJson(response, content);
	}
	
	/**
	 * @Description: 获取表结构信息列表 .<br>
	 * @param tableName 表名称 .<br>
	 * @author 郑成功 .<br>
	 * @date 2018-6-4 上午11:32:16.<br>
	 */
	@RequestMapping(value = "findTableInfos", method = { RequestMethod.GET, RequestMethod.POST })
	public void findTableInfos(HttpServletRequest request,HttpServletResponse response,String tableName){
		String dbName = MessageUtils.getMessage("connection.dbname");
		List<Map<String, Object>> list = commonMapService.selectTableInfos(dbName, tableName);
		String content = JSON.toJSONString(list);
        StringUtils.printJson(response, content);
	}
	
}
